package client;

import helper.Log;

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import remote.RemoteSpelling;

/**
 * Client for RMI spelling implementation.
 * 
 * @author the_james_marq
 * @version 28 October 13
 */
public class RMISpellingClient {
	
	/**
	 * Constructor for RMISpellingClient
	 */
    private RMISpellingClient() {}

    /**
     * Main method for client.
     * 
     * @param args Command line arguments
     */
    public static void main(String[] args) {

        try {
            Registry registry = LocateRegistry.getRegistry(args[0], Integer.parseInt(args[1]));
            RemoteSpelling stub = (RemoteSpelling) registry.lookup(args[2]);
            
            for(int i = 3; i<args.length; i++) {
            	
            	Log.out("Querying service for " + args[i]);
            	if(stub.check(args[i])==null) {
            		Log.out(args[i] + " is spelled correctly.");
            	} else {
            		if(stub.check(args[i]).size()==1) {
            			Log.out(args[i] + " is spelled incorrectly. No suggestions.");
            		} else {
            			
            			String ret_str = args[i] + " is spelled incorrectly. " + 
            					stub.check(args[i]).size() + " suggestions: ";
            			for(String s : stub.check(args[i])) {
            				ret_str += s + " ";
            			}
            			Log.out(ret_str);
            		}
            	}
            }

        } catch (Exception e) {
            Log.err("Unable to perform query.");
        }
    }
}